let arr = ['../img/f8.jpg', '../img/f9.jpg', '../img/f10.jpg', '../img/f11.jpg']
let index = 0;
//找元素box
let box = document.querySelector('.box')
//找left
let left = document.querySelector('.left')
//元素left绑定点击事件
left.onclick = function () {
    indext--
    if (indext <= 0) {
        indext = arr.length - 1
    }
    replace(index)
}
//找right
let right = document.querySelector('.right')
//元素right绑定点击事件
right.onclick = function () {
    index++
    if (index > arr.length - 1) {
        index = 0
    }
    replace(index)
}
/**
 * 描述 替换元素节点
 * @date 2020-09-27
 * @param {any} index
 * @returns {any}
 */
function replace(index) {
    let pic = document.querySelector('.pic')
    let img = pic.cloneNode(true)
    img.src = arr[index]
    box.replaceChild(img, pic)
}
//轮播图，两秒换一次
setInterval(function () {
    index++
    if (index > arr.length - 1) {
        index = 0
    }
    replace(index)
}, 2000)